
**************************************************************
* Create a dataset with parental election participation
**************************************************************

clear all
odbc load, exec("select * from riksdagsval_1982")dsn("P0846") clear

destring r, replace
drop if r == 3
drop l k
tab r, miss
gen voted1982 = r != 1
tab voted1982
drop r
duplicates tag P0846_LopNr_PersonNr, gen(duplicate)
drop if duplicate != 0
drop duplicate
compress
rename P0846_LopNr_PersonNr PersonId
save Data/tmp_parents_voted_1982, replace

use Data/data_index_workers_X_18_65_years, clear
keep PersonId
merge 1:1 PersonId using Data\data_FamilyTree
keep if _merge == 3
drop _merge
drop MorMorId MorFarId FarMorId FarFarId

rename PersonId IndexPersonId
rename MorId PersonId
merge m:1 PersonId using Data/tmp_parents_voted_1982
drop if _merge == 2
drop _merge

merge m:1 PersonId using Data/data_voting_2010
drop if _merge == 2
drop _merge

rename voted1982 Mothervoted1982
rename Voted2010 Mothervoted2010
rename PersonId MorId

rename FarId PersonId
merge m:1 PersonId using Data/tmp_parents_voted_1982
drop if _merge == 2
drop _merge

merge m:1 PersonId using Data/data_voting_2010
drop if _merge == 2
drop _merge

rename voted1982 Fathervoted1982
rename Voted2010 Fathervoted2010
rename PersonId FarId

drop MorId FarId
rename IndexPersonId PersonId 
gen ParentsVoted1982 = 0
replace ParentsVoted1982 = 1 if Mothervoted1982 == 1 | Fathervoted1982 == 1
tab ParentsVoted1982
gen ParentsVoted2010 = 0
replace ParentsVoted2010 = 1 if Mothervoted2010 == 1 | Fathervoted2010 == 1
tab ParentsVoted2010

save  Data/data_ParentsVoted, replace




